﻿package com.dbm.model;

import java.io.File;

import org.apache.log4j.Logger;

import com.dbm.util.DbUtil;
import com.dbm.util.TimerUtil;
/**
 * 读取配置文件类
 * @author wqying
 *
 */
public class ModelProp {
	Base64Model base = new Base64Model();
	String filepath = "config" + File.separator + "DBM.properties";
	Logger log = Logger.getLogger("");
	
	/**
	 * 从配置文件获取EMS 的 ip地址
	 * @return
	 * @throws Exception
	 */
	public String getEmsUrl() throws Exception{
		ReadSqlProp rsp = new ReadSqlProp();
		return ((base.deCodeBase64(rsp.readProperties(filepath, "emsUrl"))));
	}
	
	/**
	 * 从配置文件获取EMS回传的地址
	 * @return EMS回传URL
	 * @throws Exception
	 */
	public String getEmsSendBackUrl() throws Exception{
		ReadSqlProp rsp = new ReadSqlProp();
		return ((base.deCodeBase64(rsp.readProperties(filepath, "emsSendBackUrl"))));
	}
	
	
	/**
	 * 从配置文件获取ctl的ip地址
	 * @return
	 * @throws Exception
	 */
	public String getCtlUrl() throws Exception{
		ReadSqlProp rsp = new ReadSqlProp();
		return ((base.deCodeBase64(rsp.readProperties(filepath, "qmctlUrl"))));
	}
	/**
	 * 从配置文件获取查询结果最大值
	 * @return
	 * @throws Exception
	 */
	public int getSelectResultCount() throws Exception{
		ReadSqlProp rsp = new ReadSqlProp();
		return (Integer.valueOf((base.deCodeBase64(rsp.readProperties(filepath, "SelectResultCount")))));
	}
	/**
	 * 从配置文件获取查询sql 的 最大行数
	 * 
	 * @return
	 * @throws Exception
	 */
	public int getSqlCount() throws Exception {
		ReadSqlProp rsp = new ReadSqlProp();
		return (Integer.valueOf((base.deCodeBase64(rsp.readProperties(filepath, "SqlCount")))));
	}
	/**
	 * 获取标准定时器相关参数
	 * @return
	 * @throws Exception
	 */
	public TimerUtil getTimerUtilByProp(){
		TimerUtil timer = new TimerUtil();
		ReadSqlProp rsp = new ReadSqlProp();
		try {
			timer.setStartime(Long.valueOf((rsp.readProperties(filepath, "startime"))));
			timer.setCirculation(Long.valueOf((rsp.readProperties(filepath, "circulation"))));
		}catch (Exception e) {
			log.error("读取CTL接口定时器配置文件失败！");
			e.printStackTrace();
		}
		return timer;
	}
	/**
	 * 从配置文件获取数据库连接信息
	 * @return
	 * @throws Exception
	 */
	public DbUtil getJdbcUrlByProp(){
		DbUtil dbUtil = new DbUtil();
		ReadSqlProp rsp = new ReadSqlProp();
		try {
		log.info("开始读取数据库连接配置文件");
		dbUtil.setUrl(base.deCodeBase64(rsp.readProperties(filepath, "jdbcurl")));
		dbUtil.setUsername(base.deCodeBase64(rsp.readProperties(filepath, "jdbcusername")));
		dbUtil.setPassword(base.deCodeBase64(rsp.readProperties(filepath, "jdbcpassword")));
		dbUtil.setDriverClass(base.deCodeBase64(rsp.readProperties(filepath, "driverClass")));
		dbUtil.setWmsDriverClass(base.deCodeBase64(rsp.readProperties(filepath, "wmsdriverClass")));
		dbUtil.setWmsUsername(base.deCodeBase64(rsp.readProperties(filepath, "wmsuser")));
		dbUtil.setWmsUrl(base.deCodeBase64(rsp.readProperties(filepath, "wmsurl")));
		dbUtil.setWmsPassword(base.deCodeBase64(rsp.readProperties(filepath, "wmspwd")));
		dbUtil.setCtlDriverClass(base.deCodeBase64(rsp.readProperties(filepath, "CTLdriverClass")));
		dbUtil.setCtlUrl(base.deCodeBase64(rsp.readProperties(filepath, "CTLurl")));
		dbUtil.setCtlUsername(base.deCodeBase64(rsp.readProperties(filepath, "CTLusername")));
		dbUtil.setCtlPassword(base.deCodeBase64(rsp.readProperties(filepath, "CTLpassword")));
		dbUtil.setDatabasemaxnum(Integer.valueOf(base.deCodeBase64(rsp.readProperties(filepath, "databasemaxnums"))));
		dbUtil.setDatabasemaxnum(Integer.valueOf(base.deCodeBase64(rsp.readProperties(filepath, "databaseminnums"))));
		} catch (Exception e) {
			log.error("读取数据库连接配置文件失败！");
			e.printStackTrace();
		}
		return dbUtil;
	}

}
